import React from 'react';
import { Switch, Route } from 'react-router-dom';

export function getClassNames (...classNames) {
    let result = '';
    for (const className of classNames) {
        result += ' ' + className;
    }
    return result;
}

export function debounce (fn, delay) {
    let timer = null;
    return function (...args) {
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(() => {
            fn.call(this, ...args)
        }, delay);
    };
}

export function MySwitch (props) {
    return (
        <Switch>
            {
                props.routes.map((r) => (
                    <Route 
                        exact={ r.path === '/' } 
                        path={ r.path }
                        key={ r.path }
                    >
                        <r.component />
                    </Route>
                ))
            }
        </Switch>
    );

}
